DATA Statement ---------------------------------------------------------------------------- Action Stores the numeric and string constants used by a program's READ statements. Syntax DATA constant-, constant-... Remarks The constant arguments can be any valid numeric or string constant. Note You cannot use ASCII 01 and 02 in data strings if you are going to compile to an executable program. The compiler (BC.EXE) uses ASCII 01 and 02 internally to represent End-of-Statement and End-of-Line respectively. You can, however, still use 1 and 2 within the QBX environment. Names of symbolic constants (defined in a CONST statement) that appear in DATA statements are interpreted as strings, rather than as names of constants. For example, in the following program fragment, the second data item is a string, PI, and not the value 3.141593. CONST PI=3.141593 . . . DATA 2.20, PI,45,7 . . . A DATA statement can contain as many constants as will fit on a line. The constants are separated by commas. You can use any number of DATA statements. Note If a string constant contains commas, colons, or leading or trailing spaces, enclose the string in double quotation marks. Null data items (indicated by a missing value) can appear in a data list as shown below. DATA 1,2,,4,5 When a null item is read into a numeric variable, the variable has the value 0. When a null item is read into a string variable, the variable has the null string value (""). When working in the QBX environment, DATA statements can be entered only in the module-level code. BASIC moves all DATA statements not in the module-level code to the module-level code when it reads a source file. READ statements can appear anywhere in the program. DATA statements are used in the order in which they appear in the source file. You may think of the items in several DATA statements as one continuous list of items, regardless of how many items are in a statement or where the statement appears in the program. You can reread DATA statements by using the RESTORE statement. REM statements that appear at the end of DATA statements must be preceded by a colon. Without a colon, BASIC interprets trailing REM statements as string data. See Also READ, RESTORE Examples The first example displays the current date by converting the date returned by the DATE$ function. ' Use VAL to find the month from the string returned by DATE$. C$ = DATE$ FOR I% = 1 TO VAL(C$) READ Month$ NEXT DATA January, February, March, April, May, June, July DATA August, September, October, November, December ' Get the day. Day$ = MID$(C$, 4, 2) IF LEFT$(Day$, 1) = "0" THEN Day$ = RIGHT$(Day$, 1) ' Get the year. Year$ = RIGHT$(C$, 4) PRINT "Today is "; Month$; " "; Day$; ", "; Year$ Output Today is September 21, 1989 The following example shows how null data items are handled. DATA abc,,def DATA 1,,2 READ A$, B$, C$ ' B$ = "" PRINT A$, B$, C$ PRINT READ A, B, C ' B = 0 PRINT A, B, C Output abc def 1 0 2